<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../back-common.jsp"%>
<%@ include file="/WEB-INF/pages/common/taglib.jsp"%>

<%@ taglib uri="http://displaytag.sf.net" prefix="display"%>
<link href="<ls:templateResource item='/resources/plugins/select2-4.0/select2.css'/>" rel="stylesheet" />
<script src="<ls:templateResource item='/resources/plugins/select2-4.0/select2.full.min.js'/>" type="text/javascript"></script>
<script src="<ls:templateResource item='/resources/plugins/select2-4.0/i18n/zh-CN.js'/>" type="text/javascript"></script>
<script src="<ls:templateResource item='/resources/plugins/select2-4.0/makeSelect2.js'/>" type="text/javascript"></script>
<link href="<ls:templateResource item='/resources/plugins/select2-4.0/select2.css'/>" rel="stylesheet" />
	<%
		Long offset = (Long)request.getAttribute("offset");
	%>
    <form:form  action="${contextPath}/admin/weekLog/query" id="form1" method="get">
        <table class="${tableclass}" style="width: 100%">
		    <thead>
				<tr>
					<th><strong class="am-text-primary am-text-lg">首页</strong> / 项目管理 / 周报管理</th>
				</tr>
		    </thead>
		    <tbody><tr><td>
		    	    <div align="left" style="padding: 3px">
				       	    <input type="hidden" id="curPageNO" name="curPageNO" value="${curPageNO}" />
							&nbsp; 姓名
						 <%-- <ls:auth ifAnyGranted="F_AUDIT_DATA,F_VIEW_ALL_DATA">--%>
							<select name="userName" id="userName" style="width: 120px">
								<c:if test="${not empty adminUser.name}">
									<option value="${adminUser.name}">${adminUser.realName}</option>
								</c:if>
							</select> 
						<%--</ls:auth>--%>
					    
					     <select name="year" id="year" style="width: 120px">
					        <option value="0">--请选择--</option>
							<c:forEach begin="2016" end="${toYear}" varStatus="index" var="i">
								<option value="${i}" 
								<c:if test="${i eq currentYear}">selected="selected"</c:if>
								>${i}年</option>
							</c:forEach>
						 </select> 
						
					
						<select name="weekNo" id="weekNo" style="width: 120px">
						    <option value="0">--请选择--</option>
							<c:forEach begin="1" end="56" varStatus="index">
								<option value="${index.count}" 
								<c:if test="${index.count eq currentWeekNo}">selected="selected"</c:if>
								>第${index.count}周</option>
							</c:forEach>
						 </select> 
				            <input type="button" onclick="search()"  class="from1_search ${btnclass}"  value="搜索"/>
				            <input type="button" value="创建周报" class="criteria-btn" onclick="javascript:createWeeklyLog('${date}')" />
				            
				            <a href="javascript:previousWeek()"><上一周</a>
				            <a href="javascript:nextWeek()">下一周></a>
				            
				            <c:if test="${not empty startDate}">
				            	 (<fmt:formatDate value="${startDate}" pattern="yyyy年MM月dd日" />  - <fmt:formatDate value="${endDate}" pattern="yyyy年MM月dd日" />)
				            </c:if>
						<c:if test="${not empty leader.realName}">
							有问题请找师傅: ${leader.realName}
						</c:if>

				      </div>
		     </td></tr></tbody>
	    </table>
    </form:form>
    <div align="center">
          <%@ include file="/WEB-INF/pages/common/messages.jsp"%>
		<display:table name="list" requestURI="/admin/adminUser/query" id="item" export="false" sort="external" class="${tableclass}" style="width:100%">
	    	<display:column title="顺序" style="width:80px;min-width:80px;"><%=offset++%></display:column>
     		<display:column title="姓名" property="realName" style="min-width: 100px;"></display:column>
     		<display:column title="年">
     			<c:choose>
     				<c:when test="${not empty  item.year}">${item.year}</c:when>
     				<c:otherwise>${currentYear}</c:otherwise>
     			</c:choose>
     		</display:column>
     		<display:column title="周">
     			  <c:choose>
     				<c:when test="${not empty item.weekNo}">${item.weekNo}</c:when>
     				<c:otherwise>${currentWeekNo}</c:otherwise>
     			</c:choose>
     		</display:column>
     		<display:column title="工时" property="workTime" style="min-width: 80px;"></display:column>
     		<display:column title="本周周报" property="thisWeekLog" style="min-width: 200px;"></display:column>
     		<display:column title="下周计划" property="nextWeekPlan" style="min-width: 200px;"></display:column>
			<display:column title="上级" style="width:80px;min-width:80px;" property="leaderName" />
     		<display:column title="审核人" style="width:80px;min-width:80px;" property="realReviewerName" />
     		<display:column title="记录时间" style="width:150px;min-width:150px;"><fmt:formatDate value="${item.recDate }" type="both" dateStyle="long" pattern="yyyy-MM-dd hh:MM:ss" /></display:column>
	      <display:column title="操作" media="html" style="width:150px;min-width:150px;">
	      	<div class="am-btn-toolbar">
			  <div class="am-btn-group am-btn-group-xs">
			  <c:choose>
			  	<c:when test="${item.reviewed eq 1}">
					<%-- 已经审核通过 --%>
			  	    <c:if test="${not empty item.id}">
			  	        <button class="am-btn am-btn-default am-btn-xs am-text-secondary"  onclick="javascript:updateWeeklyLog('${item.id}')"><span class="am-icon-pencil-square-o"></span> 查看</button>
			  	    </c:if>
			  	</c:when>
			  	<c:otherwise>
					<%-- 尚未审核通过 --%>
			  	 <c:if test="${not empty item.id}">
			  	    <button class="am-btn am-btn-default am-btn-xs am-text-secondary"  onclick="javascript:updateWeeklyLog('${item.id}')"><span class="am-icon-pencil-square-o"></span> 修改</button>
					<button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" onclick="deleteById('${item.id}')" ><span class="am-icon-trash-o"></span> 删除</button>
					</c:if>
			  	</c:otherwise>
			  </c:choose>

			  </div>
			</div>
	      </display:column>
	      
	      
	    </display:table>
       <ls:page pageSize="${pageSize }"  total="${total}" curPageNO="${curPageNO }"  type="default"/> 
    </div>
<script src="<ls:templateResource item='/resources/plugins/My97DatePicker/WdatePicker.js'/>" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
 	makeSelect2(contextPath + "/admin/adminUser/userList","#userName","成员","value","key");
});


function createWeeklyLog(date){
		var page = contextPath + "/admin/weekLog/load?date=" + date;
		layer.open({
   		  type: 2,
   		  id: "createWeeklyLog",
   		  title: " 日期:" + date,
   		  area: ['800px','600px'],
   		  content: [page,'no'] //iframe的url，no代表不显示滚动条
   });
}	

function updateWeeklyLog(id){
	var page = contextPath + "/admin/weekLog/load/" + id;
	layer.open({
		  type: 2,
		  id: "createWeeklyLog",
		  title: " 日期:" + '${weekLog.year}' + "-" + '${weekLog.weekNo}',
		  area: ['800px','650px'],
		  content: [page,'auto'] //iframe的url，no代表不显示滚动条
});
}	

//删除
function deleteById(id) {
    layer.confirm("确定删除吗？", {
		 icon: 3
	     ,btn: ['确定','关闭'] //按钮
	   }, function(){
      	$.ajax({
        		url : "${contextPath}/admin/weekLog/delete/" +id,
        		type : "PUT",
        		dataType :"JSON",
        		async : true,
        		error : function(xhr,status,error){
        			layer.msg("网络错误,请稍后重试!");
        		},
        		success : function(result,status,xhr){
        			if(result == "success"){
        				layer.closeAll('createWeeklyLog'); //关闭信息框
        				 $('.from1_search').click();
        			}else{
        				 layer.msg("删除周报失败，审核通过的周报不能删除或者无权限删除");
        			}
        		}
        	});
	 });
  }
  
function search(){
  	$("#form1 #curPageNO").val("1");//只要是搜索,都是从第一页开始查
  	$("#form1")[0].submit();
}

function previousWeek(){
	var previous = Number($("#weekNo").val()) -1;
	$("#weekNo").val(previous);
  	$("#form1 #curPageNO").val("1");//只要是搜索,都是从第一页开始查
  	$("#form1")[0].submit();
}

function nextWeek(){
	var next = Number($("#weekNo").val()) + 1; //需要转化为数字
	$("#weekNo").val(next);
  	$("#form1 #curPageNO").val("1");//只要是搜索,都是从第一页开始查
  	$("#form1")[0].submit();
	
}

</script>
